﻿using System;
using ZyGames.Framework.Common.Security;
using ZyGames.Framework.Game.Lang;
using ZyGames.Framework.Game.Runtime;
using ZyGames.Framework.Game.Service;
using ZyGames.Framework.Game.Sns;

namespace GameServer.Script.CsScript.Action
{
	/// <summary>
	/// 1002_点击注册消息服务器返回用户名和密码
	/// </summary>
	/// <remarks>继续BaseStruct类:不检查用户合法性请求;AuthorizeAction:有验证合法性</remarks>
	public class Action2000 : BaseStruct
	{
		private string passport = string.Empty;
		private string password = string.Empty;
		private string deviceID = string.Empty;
		private int mobileType = 0;
		private int gameID = 0;
		private string retailID = string.Empty;
		private string clientAppVersion = string.Empty;
		private int ScreenX = 0;
		private int ScreenY = 0;
		private string Name = string.Empty;
		private string Pwd = string.Empty;

		public Action2000(ActionGetter actionGetter)
			: base((int)ActionType.SelfRegist, actionGetter)
		{
		}

		/// <summary>
		/// 客户端请求的参数较验
		/// </summary>
		/// <returns>false:中断后面的方式执行并返回Error</returns>
		public override bool GetUrlElement()
		{
			if (
				httpGet.GetString("DeviceID", ref deviceID) &&
				httpGet.GetString("Name", ref Name) &&
				httpGet.GetString("PWD", ref Pwd))
			{
			}
			else
			{
				return false;
			}
			return true;
		}

		/// <summary>
		/// 业务逻辑处理
		/// </summary>
		/// <returns>false:中断后面的方式执行并返回Error</returns>
		public override bool TakeAction()
		{
			Console.WriteLine("业务逻辑处理");
			try
			{
				//if (SnsManager.Register(Name, Pwd, deviceID))
				//{
				//	Console.WriteLine("创建账号成功");
				//	return true;
				//}
				//else
				//{
				//	Console.WriteLine("创建账号失败");
				//	return false;
				//}
				return true;
			}
			catch (Exception ex)
			{
				this.SaveLog(ex);
				this.ErrorCode = Language.Instance.ErrorCode;
				this.ErrorInfo = Language.Instance.St1002_GetRegisterPassportIDError;
				return false;
			}
		}
		/// <summary>
		/// 下发给客户的包结构数据
		/// </summary>
		public override void BuildPacket()
		{
			Console.WriteLine("打包下发");
			Console.WriteLine(Name);
			Console.WriteLine(Pwd);
			PushIntoStack(Name);
			PushIntoStack(Pwd);
		}

	}
}
